package com.yoyo.ad.utils;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

public class BasePresenter<T extends BaseView> {

    protected Context mContext;
    protected T mView;

    public BasePresenter(Context context, T view) {
        mContext = context;
        mView = view;
    }

    @NonNull
    protected StringBuilder getTokenId() {
        StringBuilder builder = new StringBuilder();
        String id = SPUtils.getId(mContext);
        if (StringUtil.isNull(id))
            return builder;
        else {
            builder.append("token_sign=")
                    .append(SPUtils.getToken(mContext))
                    .append("&account_id=")
                    .append(id);
            return builder;
        }
    }

    protected String getTokenIdKey() {
        StringBuilder builder = getTokenId();
        Log.i("key==", builder.toString());
        if (StringUtil.isNull(builder.toString())) {
            return "";
        } else {
            return getKey(builder);
        }
    }

    protected String getKey(StringBuilder builder) {
        return Aes.encode(builder.toString(), Aes.keyBytes);
    }

    protected boolean hasLogin() {
        return !StringUtil.isNull(getTokenIdKey());
    }
}
